package cn.edu.ujn.shi.controller;

import cn.edu.ujn.shi.dao.Msg;
import cn.edu.ujn.shi.dao.User;
import cn.edu.ujn.shi.dao.UserType;
import cn.edu.ujn.shi.service.IMessageService;
import cn.edu.ujn.shi.service.IUserService;
import cn.edu.ujn.shi.service.IUserTypeService;
import cn.edu.ujn.shi.service.MessageServiceImpl;
import cn.hutool.core.util.IdUtil;
import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.annotation.MultipartConfig;
import jakarta.servlet.http.Part;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.File;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.List;

@Controller
public class MessageController {

    @Autowired
    IMessageService messageService;

    @Autowired
    IUserService userService;
    @Autowired
    IUserTypeService iUserTypeService;

    @RequestMapping("/AListMessageServlet")
    public void aListMessageServlet(HttpServletRequest request, HttpServletResponse response) {
        try {
            response.setContentType("text/html;charset=utf-8");
            request.setCharacterEncoding("utf-8");

            String m_search = request.getParameter("search");

            List<Msg> list = messageService.getType(m_search);

            PrintWriter out = response.getWriter();
            out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
            out.println("<HTML>");
            out.println("<HEAD><TITLE>查询</TITLE></HEAD>");

            out.println("<body bgcolor='#D7E8F6'>");

            out.println("<div style='width:100%;height:58px;background:#D7E8F6;border: 1px solid ;'>");
            out.println("<div style='margin-left:480px;margin-top:10px;'>");

            out.println("<a href='AdminLoginView.jsp'><img src='images/首页.png' width='40px'/><font color='#000080'><b>首页</b></font></a>&nbsp;");
            out.println("<a href='AListUserServlet'><img src='images/用户.png' width='40px'/><font color='#000080'><b>用户信息</b></font></a>");
            out.println("<a href='AListAdminServlet'><img src='images/权限.png' width='40px'/><font color='#000080'><b>权限信息</b></font></a>");
            out.println("<a href='AListMsgServlet?search='><img src='images/aa4.png' width='40px'/><font color='red'><b>失物信息</b></font></a>");
            out.println("<a href='AListDingdanServlet'><img src='images/aa5.png' width='40px'/><font color='#000080'><b>锁定信息</b></font></a>");
            out.println("<a href='AListDiscussServlet'><img src='images/aa6.png' width='40px'/><font color='#000080'><b>评价信息</b></font></a>");
            out.println("<a href='index.jsp'><img src='images/aa7.png' width='40px'/><font color='#000080'><b>退出</b></font></a>	");
            out.println("</div>");
            out.println("</div>");

            out.println("<br/>");
            out.println("<center><img src='images/aa4.png' height=70px><font size='+4' face='楷体' color='#7D26CD'><b>失物招领信息管理</b></font></center>");
            out.println("<hr/>");

            out.println("<br/>");

            out.println("<form action='AListMsgServlet' method='post'>");
            out.println("<br/>");
            out.println("<font size='+2' face='楷体'><b>名称模糊搜索:</b></font>");
            out.println("<input type='text' name='search' size='30'/>");
            out.println("<input type='submit' value='找一找' style='width:80px;height:25px'/>");
            out.println("</form>");
            out.println("<form action='AListMsgServlet' method='post'>");
            out.println("<br/>");
            out.println("<font size='+2' face='楷体'><b>类型模糊搜索:</b></font>");
            out.println("<input type='text' name='search' size='30'/>");
            out.println("<input type='submit' value='找一找' style='width:80px;height:25px'/>");
            out.println("</form>");
            out.println("</div><hr style='height:1px;border:none;border-top:1px dashed #0066CC;'/>");

            out.println("<center>");
            out.println("<table>");
            out.println("<tr>");

            out.println("<table width=95% border=1>");
            out.println("<tr align='center' bgcolor='#E0EEE0'>");
            out.println("<td align='center'>照片</td><td>失物</td><td>类型</td><td>发布人</td><td>酬金</td><td>丢失/拾取区域</td><td>联系电话</td><td>联系位置</td><td>状态</td><td>操作</td>");
            out.println("</tr>");
            for (Msg g : list) {
                out.println("<tr align='center'>");
                out.println("<td style='width:110px;height:110px'>");
                out.println("<img src='images/pho/" + g.getPhoto() + ".jpg' width='200' height='180'/>");
                out.println("</td>");

                out.println("<td>");
                out.println(g.getName());
                out.println("</td>");
                out.println("<td>");
                out.println(g.getType());
                out.println("</td>");
                out.println("<td>");
                out.println(g.getPeople());
                out.println("</td>");
                out.println("<td>");
                out.println(g.getMoney());
                out.println("</td>");
                out.println("<td>");
                out.println(g.getArea());
                out.println("</font></td>");
                out.println("<td>");
                out.println(g.getTel());
                out.println("</td>");
                out.println("<td>");
                out.println(g.getXiaoqu());
                out.println("</font></td>");
                out.println("<td>");
                out.println(g.getFlag());
                out.println("</td>");

                out.println("<td>");
                out.println("<a href='DeleteAllMsgServlet?mid=" + g.getMid() + "'>删除</a>");
                out.println("</td>");
                out.println("</tr>");

            }
            out.println("</table>");
            out.println("<br/><hr/><img src='images/bottom.png' width='100%'>");
            out.println("</BODY>");
            out.println("</HTML>");
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("/AListMsgServlet")
    public void aListMsgServlet(HttpServletRequest request, HttpServletResponse response) {
        try {
            response.setContentType("text/html;charset=utf-8");
            request.setCharacterEncoding("utf-8");

            String m_search = request.getParameter("search");

            List<Msg> list = messageService.getAll(m_search);

            PrintWriter out = response.getWriter();
            RequestDispatcher headerDispatcher = request.getRequestDispatcher("/WEB-INF/jsp/header-admin.jsp");
            headerDispatcher.include(request, response);
            out.println("<br/>");
            out.println("<center><img src='images/aa4.png' height=70px><font size='+4' face='楷体' color='#7D26CD'><b>失物招领信息管理</b></font></center>");
            out.println("<hr/>");

            out.println("<br/>");

            out.println("<form action='AListMsgServlet' method='post'>");
            out.println("<br/>");
            out.println("<font size='+2' face='楷体'><b>名称模糊搜索:</b></font>");
            out.println("<input type='text' name='search' size='30'/>");
            out.println("<input type='submit' value='找一找' style='width:80px;height:25px'/>");
            out.println("</form>");
            out.println("<form action='AListMsgServlet' method='post'>");
            out.println("<br/>");
            out.println("<font size='+2' face='楷体'><b>类型模糊搜索:</b></font>");
            out.println("<input type='text' name='search' size='30'/>");
            out.println("<input type='submit' value='找一找' style='width:80px;height:25px'/>");
            out.println("</form>");
            out.println("</div><hr style='height:1px;border:none;border-top:1px dashed #0066CC;'/>");

            out.println("<center>");
            out.println("<table>");
            out.println("<tr>");

            out.println("<table width=95% border=1>");
            out.println("<tr align='center' bgcolor='#E0EEE0'>");
            out.println("<td align='center'>照片</td><td>失物</td><td>类型</td><td>发布人</td><td>酬金</td><td>丢失/拾取区域</td><td>联系电话</td><td>联系位置</td><td>状态</td><td>操作</td>");
            out.println("</tr>");
            for (Msg g : list) {
                out.println("<tr align='center'>");
                out.println("<td style='width:110px;height:110px'>");
                out.println("<img src='images/pho/" + g.getPhoto() + ".jpg' width='200' height='180'/>");
                out.println("</td>");

                out.println("<td>");
                out.println(g.getName());
                out.println("</td>");
                out.println("<td>");
                out.println(g.getType());
                out.println("</td>");
                out.println("<td>");
                out.println(g.getPeople());
                out.println("</td>");
                out.println("<td>");
                out.println(g.getMoney());
                out.println("</td>");
                out.println("<td>");
                out.println(g.getArea());
                out.println("</font></td>");
                out.println("<td>");
                out.println(g.getTel());
                out.println("</td>");
                out.println("<td>");
                out.println(g.getXiaoqu());
                out.println("</font></td>");
                out.println("<td>");
                out.println(g.getFlag());
                out.println("</td>");

                out.println("<td>");
                out.println("<a href='DeleteAllMsgServlet?mid=" + g.getMid() + "'>删除</a>");
                out.println("</td>");
                out.println("</tr>");

            }
            out.println("</table>");

            RequestDispatcher headerDispatcher1 = request.getRequestDispatcher("/WEB-INF/jsp/footer.jsp");
            headerDispatcher1.include(request, response);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("/AllServlet")
    public void allServlet(HttpServletRequest request, HttpServletResponse response) {
        try {

            response.setContentType("text/html;charset=utf-8");
            request.setCharacterEncoding("utf-8");

            String m_search = request.getParameter("search");
            List<Msg> list = messageService.getAll(m_search);

            PrintWriter out = response.getWriter();
            RequestDispatcher headerDispatcher = request.getRequestDispatcher("/WEB-INF/jsp/header.jsp");
            headerDispatcher.include(request, response);

            out.println("<center><hr/><img src='images/top3.jpg' width='100%'height=120px><hr/></center>");

            out.println("<br/>");
            out.println("<center><img src='images/u2.png' height=70px><font size='+4' face='楷体' color='#7D26CD'><b>全部失物招领信息</b></font></center>");
            out.println("<hr/>");


            out.println("<form action='AllServlet' method='post'>");
            out.println("<br/>");
            out.println("<img src='images/mess.png' width='50px'/>");
            out.println("<font size='+2' face='楷体' color='red'><b>失物招领信息模糊搜索</b></font>");
            out.println("<input type='text' name='search' size='20'/>");
            out.println("<input type='submit' value='找一找' style='width:120px;height:30px'/>");
            out.println("</form>");

            out.println("</div><hr style='height:1px;border:none;border-top:1px dashed #0066CC;'/>");

            out.println("<center>");
            out.println("<table>");
            out.println("<tr>");

            out.println("<table width=95% >");
            out.println("<tr>");
            out.println("<td align='center'>照片</td><td align='center'>失物</td><td align='center'>信息类型</td><td align='center'>发布人</td><td align='center'>承诺酬金</td><td align='center'>联系人位置</td><td align='center'>状态</td><td align='center'>操作</td>");
            out.println("</tr>");
            for (Msg g : list) {
                out.println("<tr>");
                out.println("<td style='width:110px;height:110px' align='center'>");
                out.println("<img src='images/pho/" + g.getPhoto() + ".jpg' width='180' height='200'/>");
                out.println("</td>");

                out.println("<td align='center'>");
                out.println(g.getName());
                out.println("</td>");
                out.println("<td align='center'>");
                out.println(g.getType());
                out.println("</td>");
                out.println("<td align='center'>");
                out.println(g.getPeople());
                out.println("</td>");
                out.println("<td align='center'>");
                out.println(g.getMoney());
                out.println("</td>");
                out.println("<td align='center'>");
                out.println(g.getXiaoqu());
                out.println("</td>");

                out.println("<td align='center'>");
                out.println(g.getFlag());
                out.println("</td>");

                if (g.getFlag().equals("未锁定")) {
                    out.println("<td align='center'>");
                    out.println("<a href='DetailServlet?mid=" + g.getMid() + "'>查看详情</a>");
                    out.println("</td>");
                    out.println("</tr>");
                }
            }
            out.println("</table>");
            RequestDispatcher headerDispatcher1 = request.getRequestDispatcher("/WEB-INF/jsp/footer.jsp");
            headerDispatcher1.include(request, response);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //修改事物招领信息
    @RequestMapping("/ChangeMsgServlet")
    public void changeMsgServlet(HttpServletRequest request, HttpServletResponse response) {
        try {
            HttpSession hs = request.getSession();
            String username = hs.getAttribute("username").toString();
            int mid = Integer.parseInt(request.getParameter("mid"));
            String name = request.getParameter("name");
            String type = request.getParameter("type");
            String people = username;
            String money = request.getParameter("money");
            String area = request.getParameter("area");
            String tel = request.getParameter("tel");
            String flag = request.getParameter("flag");
            String detail = request.getParameter("detail");
            String xiaoqu = request.getParameter("xiaoqu");

            messageService.updateMsg(new Msg(mid, name, null, type, people, money, area, tel, detail, flag, xiaoqu));
            response.sendRedirect("ListMyMsgServlet");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("/DeleteAllMsgServlet")
    public void deleteAllMsgServlet(HttpServletRequest request, HttpServletResponse response) {
        try {
            response.setContentType("text/html;charset=utf-8");
            request.setCharacterEncoding("utf-8");
            int mid = Integer.parseInt(request.getParameter("mid"));
            messageService.delete(mid);

            response.sendRedirect("AListMsgServlet?search=");
            response.sendRedirect("ListMyMsgServlet");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("/DeleteMsgServlet")
    public void deleteMsgServlet(HttpServletRequest request, HttpServletResponse response) {
        try {
            response.setContentType("text/html;charset=utf-8");
            request.setCharacterEncoding("utf-8");
            int mid = Integer.parseInt(request.getParameter("mid"));
            messageService.delete(mid);
            response.sendRedirect("ListMyMsgServlet");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("/DetailServlet")
    public void detailServlet(HttpServletRequest request, HttpServletResponse response) {
        try {
            response.setContentType("text/html;charset=utf-8");
            request.setCharacterEncoding("utf-8");
            PrintWriter out = response.getWriter();

            int mid = Integer.parseInt(request.getParameter("mid"));

            List<Msg> list = messageService.getMessage(mid);

            String name = list.get(0).getName();
            String photo = list.get(0).getPhoto();
            String type = list.get(0).getType();
            String people = list.get(0).getPeople();
            String money = list.get(0).getMoney();
            String area = list.get(0).getArea();
            String tel = list.get(0).getTel();
            String detail = list.get(0).getDetail();
            String flag = list.get(0).getFlag();
            String xiaoqu = list.get(0).getXiaoqu();

            out.println("<body bgcolor='#D7E8F6'>");

            out.println("<div style='width:100%;height:58px;background:#D7E8F6;border: 1px solid ;'>");
            out.println("<div style='margin-left:480px;margin-top:10px;'>");

            out.println("<a href='MainServlet'><img src='images/u1.png' width='40px'/><font color='red'><b>首页</b></font></a>&nbsp;");
            out.println("<a href='MyMessageServlet'><img src='images/u2.png' width='40px'/><font color='#000080'><b>个人信息</b></font></a>");
            out.println("<a href='AllServlet?search='><img src='images/u3.png' width='40px'/><font color='#000080'><b>全部信息</b></font></a>");
            out.println("<a href='MyDingdanServlet'><img src='images/u4.png' width='40px'/><font color='#000080'><b>个人锁定</b></font></a>");
            out.println("<a href='ListMyDiscussServlet'><img src='images/u5.png' width='40px'/><font color='#000080'><b>信息评价</b></font></a>");
            out.println("<a href='ListMyMsgServlet'><img src='images/u6.png' width='40px'/><font color='#000080'><b>我的信息</b></font></a>");
            out.println("<a href='index'><img src='images/u7.png' width='40px'/><font color='#000080'><b>退出</b></font></a>");
            out.println("</div>");
            out.println("</div>");

            out.println("<br/><br/><br/>");
            out.println("<center><img src='images/u3.png' height=70px><font size='+4' face='楷体' color='#7D26CD'><b>失物招领信息详情</b></font>");
            out.println("<hr/>");

            out.println("<center><table width='763' border='0' cellpadding='0' cellspacing='0'  height='25' style='border-collapse: collapse' bordercolor='#111111'><tr>");
            out.println("<td height='25'></td></tr></table>");
            out.println("<table><tr>");
            out.println("<TD vAlign=top width=120><IMG width=300 src='images/pho/" + photo + ".jpg'  width=300px align=left valign='middle'></TD>");
            out.println("<td>");
            out.println("<b>物品名称:" + name + "</b><br/><br/><br/>");
            out.println("<b>信息类型:" + type + "</b><br/><br/><br/>");
            out.println("<b>发布账号:" + people + "</b><br/><br/><br/>");
            out.println("<b>承诺酬金:【" + money + "】元</b><br/><br/><br/>");

            out.println("<b>发生区域:" + area + "</b><br/><br/><br/>");
            out.println("<b>联系人位置:" + xiaoqu + "</b><br/><br/><br/>");
            out.println("<b>联系电话:" + tel + "</b><br/><br/><br/>");
            out.println("<b>详情信息:" + detail + "</b><br/><br/><br/>");
            out.println("<b>信息状态:" + flag + "</b>");
            out.println("</td>");

            if (flag.equals("未锁定")) {
                out.println("<td>");
                out.println("<a href='GoDingServlet?mid=" + mid + "'><img src='images/zu.png' width='80px'><font size='+2' face='楷体' color='#7D26CD'><b>锁定信息</b></font></a>");
                out.println("</td>");
                out.println("</tr>");
            } else {
                out.println("<td>");
                out.println("<img src='images/ding.png' width='50px'><font size='+2' face='楷体' color='red'><b>该信息已经被锁定</b></font>");
                out.println("</td>");
                out.println("</tr>");
            }


            out.println("</table>");

            out.println("<br/><hr/><img src='images/bottom.png' width='100%'>");
            out.println("</center>");

            out.println("</body>");
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //发布失物招领信息
    @RequestMapping("/InsertMsgServlet")
    public void insertMsgServlet(HttpServletRequest request, HttpServletResponse response) {
        try {
            response.setContentType("text/html;charset=utf-8");
            request.setCharacterEncoding("utf-8");

            HttpSession hs = request.getSession();
            String people = hs.getAttribute("username").toString();
            // 设置上传路径
            //todo 改自己电脑路径
            String uploadPath = "C:\\JavaEE\\shi\\java-ee-course-defense\\src\\main\\webapp\\WEB-INF\\jsp\\images\\pho";
            Part imagePart = request.getPart("photo");
            //生成一个id存起来，这样不会有重名文件
            String simpleUUID = IdUtil.simpleUUID();
//            String fileName = Paths.get(imagePart.getSubmittedFileName()).getFileName().toString(); // 获取文件名
            Path UPLOAD_DIR = Paths.get(uploadPath);
            Path targetPath = UPLOAD_DIR.resolve(simpleUUID + ".jpg");
            Files.copy(imagePart.getInputStream(), targetPath, StandardCopyOption.REPLACE_EXISTING); // 将文件保存到服务器

            String photo = simpleUUID;
            String name = request.getParameter("name");
            String detail = request.getParameter("detail");

            String type = request.getParameter("type");

            String money = request.getParameter("money");
            String area = request.getParameter("area");
            String tel = request.getParameter("tel");
            String flag = "未锁定";

            String xiaoqu = request.getParameter("xiaoqu");

            if (request.getParameter("money") == "") {
                money = "0";
            } else {
                money = request.getParameter("money");
            }

            if (name == "" || photo == "") {
                PrintWriter out = response.getWriter();
                out.println("<script language = javascript>alert('WARING!')");
                out.println("window.history.go(-1)</script>");
            } else {

                try {
                    messageService.insert(new Msg(name, photo, type, people, money, area, tel, detail, flag, xiaoqu));
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                response.sendRedirect("ListMyMsgServlet");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("/ListMyMsgServlet")
    public String listMyMsgServlet(HttpServletRequest request, HttpServletResponse response) {
        try {
            response.setContentType("text/html;charset=utf-8");
            request.setCharacterEncoding("utf-8");

            HttpSession hs = request.getSession();
            String username = hs.getAttribute("username").toString();

            List<Msg> list = messageService.getMyMess(username);
            request.setAttribute("list", list);
            return "ListMyMsgServlet1";

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @RequestMapping("/MyMessageServlet")
    public void MyMessageServlet(HttpServletRequest request, HttpServletResponse response) {
        try {
            response.setContentType("text/html;charset=utf-8");
            request.setCharacterEncoding("utf-8");
            PrintWriter out = response.getWriter();

            HttpSession hs = request.getSession();

            //�õ��û���
            String username = hs.getAttribute("username").toString();

            List<User> list = userService.getUser(username);

            String userpass = list.get(0).getUserpass();
            String truename = list.get(0).getTruename();
            String age = list.get(0).getAge();
            String tel = list.get(0).getTel();
            String cardnumber = list.get(0).getCardnumber();
            String type = list.get(0).getType();
            RequestDispatcher headerDispatcher = request.getRequestDispatcher("/WEB-INF/jsp/header.jsp");
            headerDispatcher.include(request, response);

            out.println("<center><hr/><img src='images/top.jpg' width='100%' height=120px><hr/></center>");

            out.println("<br/>");
            out.println("<center><img src='images/u2.png' height=70px><font size='+4' face='楷体' color='#7D26CD'><b>用户账号修改</b></font>");
            out.println("<hr/>");

            out.println("<center>");
            out.println("<form action='ChangeUserServlet' method='post'>");
            out.println("<table>");
            out.println("<tr>");
            out.println("<td>");
            out.println("用户账号：");
            out.println("</td>");
            out.println("<td>");
            out.println(username);
            out.println("</td>");
            out.println("</tr>");

            out.println("<tr>");
            out.println("<td>");
            out.println("用户密码：");
            out.println("</td>");
            out.println("<td>");
            out.println("<input type='text' name='userpass' style='width:300px;' value=" + userpass + ">");
            out.println("</td>");
            out.println("</tr>");
            out.println("<tr>");
            out.println("<td>");
            out.println("真实姓名：");
            out.println("</td>");
            out.println("<td>");
            out.println("<input type='text' name='truename' style='width:300px;' value=" + truename + ">");
            out.println("</td>");
            out.println("</tr>");

            out.println("<tr>");
            out.println("<td>");
            out.println("用户年龄：");
            out.println("</td>");
            out.println("<td>");
            out.println("<input type='text' name='age' style='width:300px;' value=" + age + ">");
            out.println("</td>");
            out.println("</tr>");

            out.println("<tr>");
            out.println("<td>");
            out.println("联系方式：");
            out.println("</td>");
            out.println("<td>");
            out.println("<input type='text' name='tel' style='width:300px;' value=" + tel + ">");
            out.println("</td>");
            out.println("</tr>");

            out.println("<tr>");
            out.println("<td>");
            out.println("身份证号：");
            out.println("</td>");
            out.println("<td>");
            out.println("<input type='text' name='cardnumber' style='width:300px;' value=" + cardnumber + ">");
            out.println("</td>");
            out.println("</tr>");

            out.println("<tr>");
            out.println("<td>");
            out.println("身份类型：");
            out.println("</td>");
            out.println("<td>");
            out.println("<select name='type' style='width:300px;'>");
            List<UserType> list1 = iUserTypeService.getAll();
            for (UserType userType : list1) {
                out.println("<option value = '" + userType.getId() + "'" + (type != null && type.equals(userType.getId() + "") ? "selected" : "") + " > " + userType.getType() + " </option >");
            }
            out.println("</select>");
            out.println("</td>");
            out.println("</tr>");

            out.println("<tr>");
            out.println("<td colspan='2'>");
            out.println("<input type='submit' value='更改' style='width:400px;'/>");
            out.println("</td>");
            out.println("</tr>");
            out.println("</table>");

            out.println("</form>");
            out.println("</center>");
            RequestDispatcher headerDispatcher1 = request.getRequestDispatcher("/WEB-INF/jsp/footer.jsp");
            headerDispatcher1.include(request, response);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("/UpdateServlet")
    public String UpdateServlet(HttpServletRequest request, HttpServletResponse response) {
        try {

            response.setContentType("text/html;charset=utf-8");
            request.setCharacterEncoding("utf-8");
            PrintWriter out = response.getWriter();




            int mid = Integer.parseInt(request.getParameter("mid"));

            List<Msg> list = messageService.getMessage(mid);
            request.setAttribute("msg", list.get(0));
            return "UpdateServlet1";
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}

